package com.lesshassles.controller;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.lesshassles.model.User;

/**
 * Validator for SignInController
 * 
 * @author David Santoro
 * @see com.lesshassles.controller.SignInController
 */
public class SignInValidator implements Validator {
	
	public boolean supports(Class aClass) {
		return aClass.equals(User.class);
	}

	/**
	 * Validates an Employee command object. Ensures that employeeId is greater
	 * than zero and that a password is specified.
	 * 
	 * @see Employee
	 */
	public void validate(Object command, Errors errors) {
		User user = (User) command;
		if (user == null)
			return;
		String email = user.getEmail();
		String password = user.getPassword();

		// Validate email
		if (email == null || email.equals("")) {
			errors.reject("error.login.invalid");
		} else if (password == null || password.trim().length() < 8
				|| password.trim().length() > 10) {
			errors.reject("error.login.invalid");
		}
	}
}
